package com.jinzecloud.reportapproval.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.jinzecloud.reportapproval.bean.Admin;
import com.jinzecloud.reportapproval.dto.Param;
import com.jinzecloud.reportapproval.service.AdminService;
import com.jinzecloud.reportapproval.utils.PageUtils;
import com.jinzecloud.reportapproval.utils.R;
import com.jinzecloud.reportapproval.vo.AdminRoleVo;
import com.jinzecloud.reportapproval.vo.AdminVo;
import com.jinzecloud.reportapproval.vo.AdminVos;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * 管理员表
 *
 * @author æ­å°
 * @email 1971240051@qq.com
 * @date 2024-09-03 12:10:45
 */
@RestController
@RequestMapping("reportApproval/admin")
@Api(tags = "管理员表", description = "管理员表", value = "管理员表")
public class AdminController {
    @Autowired
    private AdminService adminService;

    /**
     * 列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ApiOperation(value = "管理员表列表",notes = "管理员表列表")
    //@RequiresPermissions("reportApproval:admin:list")
    public R list(@RequestBody Param param){
        PageUtils page = adminService.queryPage(param);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping(value = "/info/{adId}",method = RequestMethod.POST)
    @ApiOperation(value = "管理员表信息",notes = "管理员表信息")
    //@RequiresPermissions("reportApproval:admin:info")
    public R info(@PathVariable("adId") Integer adId){
        AdminVos adminRoleVo = adminService.getByIdRoleUser(adId);

        return R.ok().put("admin", adminRoleVo);
    }

//    /**
//     * 保存
//     */
//    @RequestMapping(value = "/save",method = RequestMethod.POST)
//    @ApiOperation(value = "管理员表保存",notes = "管理员表保存")
//    //@RequiresPermissions("reportApproval:admin:save")
//    public R save(@RequestBody Admin admin){
//		R r = adminService.saveAdmin(admin);
//
//        return r;
//    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ApiOperation(value = "管理员表修改",notes = "管理员表修改")
    //@RequiresPermissions("reportApproval:admin:update")
    public R update(@RequestBody AdminVos adminRoleVo){
		adminService.updateByIdAdminRoleVo(adminRoleVo);

        return R.ok();
    }

    @RequestMapping(value = "/getByIdAndName",method = RequestMethod.GET)
    @ApiOperation(value = "管理员表通过id和name查询",notes = "管理员表通过id和name查询")
    public R getByIdAndName(){
		List<Admin> adminList = adminService.getByIdAndName();

        return R.ok().put("adminList", adminList);
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ApiOperation(value = "管理员表删除",notes = "管理员表删除")
    //@RequiresPermissions("reportApproval:admin:delete")
    public R delete(@RequestBody Integer[] adIds){
		adminService.removeByIds(Arrays.asList(adIds));

        return R.ok();
    }


    @ApiOperation("上传文件")
    @PostMapping("/fileUplod")
    public R fileUplod(String adminId, @RequestPart MultipartFile file) throws IOException {
        R r = adminService.fileUplod(adminId,file);
        return r;
    }

    /**
     * 用户绑定角色
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ApiOperation(value = "用户绑定角色",notes = "用户绑定角色")
    public R bindingRole(@RequestBody AdminRoleVo adminRoleVo){
		R r = adminService.saveAdmin(adminRoleVo);

        return r;
    }
}
